﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace housingsafety.server.Models
{
    /// <summary>
    /// 用户信息
    /// </summary>
    public class UserDto
    {
        /// <summary>
        /// 用户ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 用户编号
        /// </summary>
        public string Number { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string Uname { get; set; }
        /// <summary>
        /// 姓名
        /// </summary>
        public string Nickname { get; set; }
        /// <summary>
        /// 手机号
        /// </summary>
        public string Phone { get; set; }
        /// <summary>
        /// 是否管理员
        /// </summary>
        public bool? SysAdmin { get; set; }
        /// <summary>
        /// 角色类型
        /// </summary>
        public PermissionRoleType Role { get; set; }
        /// <summary>
        /// 身份证号
        /// </summary>
        public string IdCard { get; set; }
        /// <summary>
        /// 行政区
        /// </summary>
        public SimpleDepartmentDto District { get; set; }
        /// <summary>
        /// 管辖区域
        /// </summary>
        public List<SimpleDepartmentDto> JurisdictionCodes { get; set; }
        /// <summary>
        /// 管辖区域中文
        /// </summary>
        public List<string> JurisdictionNames { get; set; }
        /// <summary>
        /// 行政区Json,用于前端编辑用户路径还原使用
        /// </summary>
        public string DistrictJson { get; set; }
        /// <summary>
        /// 管辖区域Json,用于前端编辑用户路径还原使用
        /// </summary>
        public string JurisdictionJson { get; set; }
        /// <summary>
        /// 用户组
        /// </summary>
        public UserGroupType UserGroup { get; set; }
        /// <summary>
        /// 是否被禁用
        /// </summary>
        public bool? Disabled { get; set; }
        /// <summary>
        /// 是否被删除
        /// </summary>
        public bool? IsDelete { get; set; }
        /// <summary>
        /// 删除时间
        /// </summary>
        public DateTime? DeleteTime { get; set; }

        public string CreateBy { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateOn { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? ModifiedOn { get; set; }
        /// <summary>
        /// 登录次数
        /// </summary>
        public int? LoginCount { get; set; }
        /// <summary>
        /// 角色显示名
        /// </summary>
        public string RoleName
        {
            get
            {
                string displayName = string.Empty;
                var objs = Role.GetType().GetField(Role.ToString())
                    .GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (objs.Length > 0)
                {
                    var descriptionAttribute = objs[0] as DescriptionAttribute;
                    if (descriptionAttribute != null)
                    {
                        displayName = descriptionAttribute.Description;
                    }
                }

                return displayName;
            }
        }
        /// <summary>
        /// 用户组显示名
        /// </summary>
        public string UserGroupName
        {
            get
            {
                string displayName = "超级管理员";
                if (UserGroup != UserGroupType.Unknown)
                {
                    var objs = UserGroup.GetType().GetField(UserGroup.ToString())
                    .GetCustomAttributes(typeof(DescriptionAttribute), false);
                    if (objs.Length > 0)
                    {
                        var descriptionAttribute = objs[0] as DescriptionAttribute;
                        if (descriptionAttribute != null)
                        {
                            displayName = descriptionAttribute.Description;
                        }
                    }
                }

                return displayName;
            }
        }

        /// <summary>
        /// 所在单位ID
        /// </summary>
        public string SurveyUnitId { get; set; }

        /// <summary>
        /// 所在单位名称
        /// </summary>
        public string UnitName { get; set; }
    }
}